package com.aid.winter.controller;

import com.aid.winter.common.annotation.RequiredRole;
import com.aid.winter.common.constant.RoleConstants;
import com.aid.winter.common.response.Result;
import com.aid.winter.dto.request.ClothesStyleCreateRequest;
import com.aid.winter.dto.response.ClothesStyleVO;
import com.aid.winter.dto.response.PageResult;
import com.aid.winter.service.ClothesStyleService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 衣服款式管理控制器
 */
@RestController
@RequestMapping("/clothes/style")
@RequiredArgsConstructor
public class ClothesStyleController {

    private final ClothesStyleService styleService;

    /**
     * 创建款式（仅学校用户和超管可操作）
     */
    @PostMapping
    @RequiredRole({4, 5})
    public Result<ClothesStyleVO> createStyle(@Validated @RequestBody ClothesStyleCreateRequest request) {
        return Result.ok(styleService.createStyle(request));
    }

    /**
     * 更新款式（仅学校用户和超管可操作）
     */
    @PutMapping("/{id}")
    @RequiredRole({4, 5})
    public Result<ClothesStyleVO> updateStyle(
            @PathVariable Long id,
            @Validated @RequestBody ClothesStyleCreateRequest request) {
        return Result.ok(styleService.updateStyle(id, request));
    }

    /**
     * 删除款式（仅学校用户和超管可操作）
     */
    @DeleteMapping("/{id}")
    @RequiredRole({4, 5})
    public Result<Void> deleteStyle(@PathVariable Long id) {
        styleService.deleteStyle(id);
        return Result.ok();
    }

    /**
     * 获取款式详情
     */
    @GetMapping("/{id}")
    public Result<ClothesStyleVO> getStyleDetail(@PathVariable Long id) {
        return Result.ok(styleService.getStyleDetail(id));
    }

    /**
     * 查询款式列表
     */
    @GetMapping("/list")
    public Result<PageResult<ClothesStyleVO>> listStyles(
            @RequestParam(required = false) Integer gender,
            @RequestParam(required = false) Integer status,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.ok(styleService.listStyles(gender, status, pageNum, pageSize));
    }

    /**
     * 更新款式状态（仅学校用户和超管可操作）
     */
    @PutMapping("/{id}/status")
    @RequiredRole({4, 5})
    public Result<Void> updateStatus(
            @PathVariable Long id,
            @RequestParam Integer status) {
        styleService.updateStatus(id, status);
        return Result.ok();
    }
} 